;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Report.Arledger", [])
        .controller("ArledgerCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$filter", "$timeout", "UserContextService", "$stateParams", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $filter, $timeout, UserContextService, $stateParams) {
            $scope.markInfo = {
                curRow: -1
            };

            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };

            $scope.exportParam = {
                allUrl: ybHttp.RequestUrl("dReport", "/newreport/exprotSumRece")
            };

            $scope.toolbarConfig = {
                showAdvanceSearch: false,
                showColConfig: false,
            };
            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.condition = {};
            $scope.dataList = [];

            $scope.tbConf = {
                scrollWidth: 2000,
                tableCol: [
                    {
                        name: "客户编码",
                        dataField: "dealerCode",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "客户名称",
                        dataField: "delaerName",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "月初应收余额",
                        dataField: "ycys",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "本月开票金额",
                        dataField: "invoicedMoney",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "本月回款金额",
                        dataField: "rebackMoney",
                        width: 160,
                        isShow: true
                    },
                    {
                        name: "截止到本月末开票总应收账款",
                        dataField: "ys",
                        width: 160,
                        isShow: true
                    },
                    {
                        name: "其中：逾期应收",
                        dataField: "overdueMoney",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "次月总应还",
                        dataField: "nextMoney",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "发货未开票应收",
                        dataField: "unInvoicedMoney",
                        width: 140,
                        isShow: true
                    }
                ]
            };

            $scope.reset = function () {
                $scope.condition = {};
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            $scope.selectRow = function (index) {
                $scope.markInfo.curRow = index;
            };

            $scope.checkDate = function (obj, startFiled, endFiled) {
                var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
                if (!!timeFormatObj.tStart) {
                    obj[startFiled] = timeFormatObj.tStart;
                }
                if (!!timeFormatObj.tEnd) {
                    obj[endFiled] = timeFormatObj.tEnd;
                }
            };

            function getDataList(curPage) {
                $scope.markInfo.curRow = -1;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }

                var service = "dReport";
                var reqUrl = "/newreport/sumRece";
                var param = {
                    pageNum: $scope.pageInfo.curPage,
                    pageSize: $scope.pageInfo.pageSize,
                    filters: angular.copy($scope.condition)
                };
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.createDateShow = $filter("YbDate")(item.createDate, 'yyyy-MM-dd HH:mm:ss');
                        item.invoiceDateShow = $filter("YbDate")(item.invoiceDate, 'yyyy-MM-dd HH:mm:ss');

                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }

            (function () {
                getDataList();
            })();
        }])
    ;
})(window, window.angular);